package com.shouhuobao.take.wallet.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shouhuobao.station.R;
import com.shouhuobao.take.model.CapitalHistoryBean;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;

/**
 * Created by joker on 2017/8/5.
 * 资金记录适配器
 */
public class CapitalHistoryAdapter extends BaseAdapterExt<CapitalHistoryBean> {

    private String residueMoneyStr = "剩余  %1$s";

    public CapitalHistoryAdapter(ArrayList<CapitalHistoryBean> items, Activity context) {
        super(items, context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_wallet_capitalhistory, parent, false);
            holder.titleTV = (TextView) convertView.findViewById(R.id.title_TV);
            holder.moneyTV = (TextView) convertView.findViewById(R.id.money_TV);
            holder.dateTV = (TextView) convertView.findViewById(R.id.date_TV);
            holder.residueMoneyTV = (TextView) convertView.findViewById(R.id.residue_money_TV);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final CapitalHistoryBean item = items.get(position);
        holder.titleTV.setText(item.getTypeDesc());
        if (item.getType() == 11 || item.getType() == 21 || item.getType() == 31) {
            holder.moneyTV.setText("+" + item.getMoney());
        } else {
            holder.moneyTV.setText("-" + item.getMoney());
        }
        holder.dateTV.setText(item.getCreateTime());
        holder.residueMoneyTV.setText(String.format(residueMoneyStr, item.getBalance()));
        return convertView;
    }

    private class ViewHolder {
        TextView titleTV;//记录标题
        TextView moneyTV;//操作的金额
        TextView dateTV;//日期
        TextView residueMoneyTV;//剩余金额
    }
}
